#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+5;
const int maxA=1e6+5;
int h[maxA];
int p[maxn];
int a[maxn];
int n,t;
int dp[maxn][2];
int pre[maxn][2];

signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        p[i]=h[a[i]];
        h[a[i]]=i;
    }
    for(int i=2;i<=n;i++){
        dp[i][0]=dp[i][1]=max(dp[i-1][0],dp[i-1][1]);
        if(p[i]==0) continue;
        dp[i][0]=max(dp[i-1][1]-dp[p[i]][1]+dp[p[i]][0]+a[i],dp[i][0]);
        dp[i][1]=max(dp[i-1][0]-dp[p[i]][0]+dp[p[i]][1]+a[i],dp[i][1]);
    }
    cout<<max(dp[n][1],dp[n][0])<<endl;
    memset(h,0,sizeof(h));
    }
    return 0;
}
